<template>
    <el-form-item :label-width="item.labelWidth?item.labelWidth:'130px'" :label="item.title" :prop="rules?item.field:''">
      <span slot="label">{{item.title}}
        <el-tooltip v-if="item.info" :content="item.info" placement="top">
          <span class="fas fa-info-circle color"></span>
        </el-tooltip>
      </span>
     <el-select @change="change" v-model="form[item.field]" :disabled="disabled" filterable placeholder="请选择" style="width: 100%;">
        <el-option
          v-for="obj in list"
          :key="obj.id + ''"
          :label="obj.name"
          :value="obj.id + ''">
        </el-option>
      </el-select>
    </el-form-item>
</template>

<script>
import { getSelectedByUrl } from '../../../api/common';
export default {
  props: ['item', 'form', 'rules', 'disabled', 'url'],
  data() {
    return {
      list: []
    };
  },
  beforeCreate() {

  },
  mounted() {
    // console.log(this.form)
    // if(this.form[this.item.field] === undefined || this.form[this.item.field] === ''){
    //   this.form[this.item.field] = '';
    // }else{
    //   this.form[this.item.field] = this.form[this.item.field] + ''
    // }
    if (this.item.init) {
      this.item.init(this.form, this.item);
    }
    getSelectedByUrl(this.item.url).then(response => {
      if (response.success) {
        if (response.data) {
          this.list = response.data;
        } else {
          this.list = [];
        }
      }
    });
  },
  methods: {
    change(v) {
      if (this.item.itemChange) {
        this.item.itemChange(this.form, this.item, v);
      }
    }
  }
};
</script>

